package com.visp.midiproxy;

import java.util.Observable;

import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;

public class MonitoringReceiver
	extends Observable
    implements Receiver
{
	
    public void send(MidiMessage theMessage, long timeStamp)
    {
        byte byteData[] = theMessage.getMessage();
        int status = byteData[0] & 0xff;
        int command = status & 0xf0;
        int channel = status & 0xf;
        
        switch(command)
        {
        case 144: 
        	setChanged();
            if(byteData[2] != 0) {
//            	System.out.println("NOTE ON: " + byteData[1]);
            	notifyObservers(new MidiData(MidiData.TYPE_NOTE_ON, channel, byteData[1], byteData[2]));
            } else {
//            	System.out.println("NOTE OFF: " + byteData[1]);
            	notifyObservers(new MidiData(MidiData.TYPE_NOTE_OFF, channel, byteData[1], byteData[2]));
            }
            break;

        case 128: 
//        	System.out.println("NOTE OFF: " + byteData[1]);
        	setChanged();
        	notifyObservers(new MidiData(MidiData.TYPE_NOTE_OFF, channel, byteData[1], byteData[2]));
            break;

        case 224: 
//            win.showPitchBend(channel, byteData[1], byteData[2]);
            break;

        case 160: 
//            win.showPolyKeyPressure(channel, byteData[1], byteData[2]);
            break;

        case 176:
//        	System.out.println("CC: " + byteData[1] + ", " + byteData[2]);
        	setChanged();
        	notifyObservers(new MidiData(MidiData.TYPE_CONTROLLER, channel, byteData[1], byteData[2]));
            break;

        case 192: 
//            win.showProgramChange(channel, byteData[1]);
            // fall through

        case 208: 
//            win.showChannelPressure(channel, byteData[1]);
            // fall through

        default:
            if(status == 254)
            {
//                win.showActiveSensing();
                break;
            }
            if(status == 248) {
//                win.showTimingClock();
            } else {
//                win.showOtherMessage();
            }
            break;
        }
    }

    public void close()
    {
    }
}
